package aiaudio.storage.simple;

import aiaudio.storage.api.IArtist;
import aiaudio.storage.api.IAudioTestSet;
import aiaudio.storage.api.IAudioTrainingSet;
import aiaudio.storage.api.IUser;
import aiaudio.storage.api.RevereUserArtistTuple;
import java.util.HashMap;
import java.util.List;

/**
 *
 * @author Nastya
 */
public class SimpleIncludeAudioTrainingStorage extends TrainingStorage {

    public static final int ARTISTS_MIN_COUNT = 3;
    public static final int USERS_MIN_COUNT = 2;
    private static final double ARTIST_CUTTING = 0.66;
    private static final int USERS_CUTTING = 2;
    private String name;

    public String getName() {
        return name;
    }

    public SimpleIncludeAudioTrainingStorage(String name, List<IUser> users,
            List<IArtist> artists,
            HashMap<RevereUserArtistTuple, Double> ratings)
            throws TooManyItemsException {
        super(users, artists, ratings);
        this.name = name;
    }

    @Override
    protected void splitToTrainingSets(List<IUser> users, List<IArtist> artists,
            HashMap<RevereUserArtistTuple, Double> ratings)
            throws TooManyItemsException {
        int usersCount = users.size();
        int artistsCount = artists.size();

        if (usersCount < USERS_MIN_COUNT || artistsCount < ARTISTS_MIN_COUNT) {
            throw new TooManyItemsException(usersCount, artistsCount);
        }
        int artistCut = (int) (artistsCount * ARTIST_CUTTING);
        int usersCut = usersCount / USERS_CUTTING;

        StorageSplitter splitter = new StorageSplitter(users, artists, ratings);

        IAudioTrainingSet trainingSet = splitter.extractTrainingSet(
                0, artistCut,
                0, usersCount);
        addTrainingSetSet(trainingSet);

        trainingSet = splitter.extractTrainingSet(
                artistCut, artistsCount,
                0, usersCut);
        addTrainingSetSet(trainingSet);

        IAudioTestSet testSet = splitter.extractTestSet(
                artistCut, artistsCount, usersCut, usersCount);
        setTestSet(testSet);

    }
    
//    public static SimpleIncludeAudioTrainingStorage readFromFile(String filename){
//        
//    }
}
